package com.myapp.model;
import java.io.Serializable;
import java.util.Date;
import javax.jdo.annotations.*;

import com.google.appengine.api.users.User;

/*
	A user provides a valueobject to a property.
	A valueobject is weird though:
		- If a user is setting a value that already exists
			that valueobject is associated to the PropertyValue object.
		- If a user is setting a value that does not exist, a new valueobject
			is created. 
		- A valueobject is immutable, however: once set, it must never be modified.
	
	OK, here is where a design comes in handy. How to represent 
	a value object. I believe the shortest path is distinct properties
	for each valuetype. What is the client impact?
	ValueObject v = new ValueObject();
	v.valueType = typeof(somevalue);
	v.setValue(somevalue);
	
	Object v = somevalue;
	//persist
	
	Get every PropertyValue that has a ValueObject.value of 5.
	Groups are based on ValueObjects.
*/

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Query(name="latestPropertys",
       value="select from com.myapp.model.Property order by date desc range 0,5")
public class ValueObject implements Serializable
{
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    @Persistent(nullValue = NullValue.EXCEPTION)
    private ValueType valueType;
    
    @Persistent
    private int intValue;
    
    @Persistent
    private String stringValue;
    
    @Persistent
    private boolean booleanValue;
    
    @Persistent
    private Location locationValue; //there must be a location datatype out there
    
    @Persistent
    private String colorValue;
    
    @Persistent
    private byte[] imageValue;
    
    @Persistent
    private String linkValue;
    
    @Persistent
    private Date dateValue;

	@Persistent
	private String embedValue;
	
    public ValueObject() {
    }

	public Object getValue()
	{
		switch (this.valueType)
		{
			case INT:
			{
				return intValue;
			}
			default:
			{
				return stringValue;
			}
		}
	}
    public Long getId() {
        return id;
    }

    public ValueType getValueType() {
        return valueType;
    }

    public void setIntValue(int v)
    {
    	this.intValue = v;
    }
    public void setStringValue(String v)
	{
    	this.stringValue = v;
    }


}
